import React, { useState, useEffect, createContext, useContext } from 'react';
import { isLoginContext } from '../../../pages/My/my'
import './login.less'
const Login = (props) => {
    // console.log(props, 'props');
    const { ChangeisLogin, username, password } = props
    const [inputusername, setUsername] = useState("");
    const [inputpassword, setPassword] = useState("");
    const [i, setI] = useState(1);
    const handleSubmit = async e => {
        e.preventDefault();
        console.log(inputusername, 'inputusername');
        console.log(inputpassword, 'inputpassword');
        
        if (username == inputusername && password == inputpassword) {
            console.log('密码正确');
            localStorage.setItem('username', username)
            localStorage.setItem('password', password)
            ChangeisLogin()

        } else {
            console.log('密码错误');
            alert('用户名或密码错误')
        }
        // console.log(localStorage.getItem("username"),'username');
        // if(localStorage.getItem(input.value)){
        //     console.log(localStorage.getItem(target.value));
        // }else{
        //     console.log('用户名不存在');
        // }
        // localStorage.setItem(`username${i}`, username)
        // localStorage.setItem(`password${i}`, password)
        // setI(i + 1)
        console.log('点击了登录');


    };


    // useEffect(() => {
    //     const loggedInUser = localStorage.getItem("user");
    //     // console.log(loggedInUser);
    //     if (loggedInUser) {
    //         const foundUser = JSON.parse(loggedInUser);
    //         setUser(foundUser);
    //         console.log('之前登录过');
    //     }
    // }, []);
    return (
        <>

            <div className='login'>
                <form onSubmit={handleSubmit} className='login-form' >
                    <div className="input-list">
                        <div style={{ fontFamily: 'LiShu', display: 'block' }} htmlFor="username" className='login-label'>用户名: </div>
                        <input
                            type="text"
                            className='input'
                            // value={username}
                            placeholder="输入用户名"
                            onChange={({ target }) => setUsername(target.value)}
                        />
                    </div>
                    {/* <br /> */}
                    <div className="input-list">


                        <div style={{ fontFamily: 'LiShu', display: 'block' }} htmlFor="password" className='login-label'>密码: </div>
                        <input
                            className='input'
                            type="password"
                            // value={password}
                            placeholder="输入密码"
                            onChange={({ target }) => setPassword(target.value)}
                        />
                    </div>
                    <br />
                    <div className="loginbutton">
                        <button style={{ fontFamily: 'LiShu', display: 'block' }} type="submit">登录</button>
                        
                    </div>
                </form>
            </div>

        </>
    )
}

export default Login